{
  "name": "Expense Reimbursement Processing Agent",
  "nodes": [
    {
      "parameters": {
        "updates": ["message"]
      },
      "id": "c731efc1-ae71-4307-9f89-105707053ab2",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "employee_message",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "name": "employee_name",
              "value": "={{ $json.message.from.first_name + ' ' + ($json.message.from.last_name || '') }}",
              "type": "string"
            },
            {
              "name": "chat_id",
              "value": "={{ $json.message.chat.id }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "6cabe2c5-687f-443d-b463-ef8475690066",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [224, 0]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Employee Name: {{ $json.employee_name }}\nEmployee Message: {{ $json.employee_message }}\nChat ID: {{ $json.chat_id }}",
        "options": {
          "systemMessage": "=You are an Expense Reimbursement Processing Assistant.\n\nYour responsibilities:\n1. Identify whether the employee wants to SUBMIT a new expense reimbursement or CHECK reimbursement status.\n\n2. For new expense submissions, collect:\n   - Employee ID\n   - Expense Date\n   - Expense Category (Travel, Meals, Client Expense, Accommodation, Other)\n   - Expense Amount\n   - Brief description\n\n3. Validate the employee using the Employee Master Tool and extract:\n   - Employee_Name\n   - Employee_Email (used for email communication)\n   - Employment_Status\n\n4. If the employee is Active:\n   - Generate a reimbursement reference ID in format:\n     EXP-YYYYMMDD-[last 4 digits of employee]-HHmmss\n   - Register the expense using the Expense Register Tool\n   - Send acknowledgement email using Gmail Tool to Employee_Email\n   - Explain approval workflow and reimbursement timeline\n   - Respond using Telegram Response Tool\n\n5. If the employee is Inactive or invalid:\n   - Politely explain the reason\n   - Do NOT register the expense\n   - Respond using Telegram Response Tool\n\n6. For status checks:\n   - Ask for reimbursement reference ID if missing\n   - Retrieve status using the Expense Status Tool\n   - Explain current approval stage and next steps\n   - Respond using Telegram Response Tool\n\nStrict rules:\n- Do NOT guarantee reimbursement approval.\n- Do NOT provide tax advice.\n- Be clear, professional, and empathetic.\n- Employee email must be retrieved from Employee Master Tool.\n- ALWAYS use the Telegram Response Tool."
        }
      },
      "id": "9d2cca22-884a-4892-b374-79c4980d95be",
      "name": "Expense Reimbursement Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [496, 0]
    },
    {
      "parameters": {
        "model": { "mode": "id", "value": "gpt-4o" },
        "options": { "temperature": 0.2 }
      },
      "id": "04036e56-68a8-4050-ad6b-04a52098e891",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [320, 224]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Workflow Configuration').item.json.chat_id }}"
      },
      "id": "2bb94d6d-2e68-4a5c-942c-c23477d2c0f7",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [480, 224]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Validate employee and retrieve email and status."
      },
      "id": "3102787d-3f1a-464f-979b-7a75d83d58c6",
      "name": "Employee Master Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [624, 256]
    },
    {
      "parameters": {
        "operation": "append",
        "descriptionType": "manual"
      },
      "id": "9cd9729e-6d1d-418e-bfec-8d25b2d74205",
      "name": "Expense Register Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [784, 256]
    },
    {
      "parameters": {
        "descriptionType": "manual"
      },
      "id": "1deb2a1f-6831-4a63-a496-81182bc33046",
      "name": "Expense Status Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [928, 320]
    },
    {
      "parameters": {
        "sendTo": "={{ $fromAI('employee_email') }}",
        "subject": "={{ $fromAI('email_subject', '', 'string', 'Expense Reimbursement Submitted') }}",
        "message": "={{ $fromAI('email_body') }}"
      },
      "id": "c736cbfc-6c4b-458d-b4c4-0ffcd386101b",
      "name": "Gmail Tool",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [1072, 224]
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}"
      },
      "id": "f80926a8-64c7-4a26-bcd1-69ce6ccb5cbf",
      "name": "Send Telegram Response",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [928, 0]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [[{ "node": "Workflow Configuration", "type": "main" }]]
    },
    "Workflow Configuration": {
      "main": [[{ "node": "Expense Reimbursement Agent", "type": "main" }]]
    },
    "Expense Reimbursement Agent": {
      "main": [[{ "node": "Send Telegram Response", "type": "main" }]]
    }
  },
  "active": false
}
